import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Delete from '#cpt/temp/Delete'
import Controls from '#cpt/temp/Controls'
import AddEditModal from '#cpt/temp/AddEditModal'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// =====================================================================Lazy
const Page 				= $Lazy.load(()=>import('#tp/page/page-container'))
const Box 				= $Lazy.load(()=>import('#tp/box/box'))
const PermissionName 	= $Lazy.state(()=>import('./cpt/permission-name'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys: [],
		selectedRows: [],
		// 搜索表单列表
		forms : [
			{ label: '名称',		name: 'scene_name' },
		],
		// 提交表单列表
		formData : [
			{ label: '名称',		name: 'scene_name',		required:true,	full:true },
			{ label: '状态',		name: 'scene_status',	required:true,	full:true,	type: 'select',	data:[
				{name: '启用', value: '1'},	{name: '未启用', value: '0'}
			]},
			{ label: '排序',		name: 'scene_sort',		required:true,	full:true,	value: 50 },
			{ label: '备注',		name: 'scene_remark',	full:true,	type: 'textarea' },
		]
	}
	model = {}
	
	componentDidMount(){
		this.fetch()
	}
	// paging
	fetch = () => $fn.fetch.call(this,'conf-scene/index')
	
	// 表单
	cols = [
		{ title: '名称',			dataIndex: 'scene_name',		width:100 },
		{ title: '状态',			dataIndex: 'scene_status',		width:100,	render: text => text === '1' ? '启用' : '未启用' },
		{ title: '备注',			dataIndex: 'scene_remark',		width:150, },
		TableControls.controls.call(this,{ width: 60 }),
	]
	
	// 表格操作按钮
	table_controls = (text, rows) => [
		TableControls.edit.call(this, null, null, { rows } ),
	]
	// 操作按钮
	controls = () =>  [
		Controls.add.call(this),
		this.onDel()
	]
	
	// 删除
	onDel = uuid => Delete.call(this, 'conf-scene/del', { uuid, isKeys: !uuid, idStr: 'uuids' })
	
	render(){
		return (
			<>
				<Page title='场景权限管理' nobc>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					<div className='fx ex mt5'>
						<Box title='场景列表' className='ex' flex contentClassName='rel fv xplr mt10' controls={this.controls()}>
							{  Table.call(this, { wrapClassName: 'mlr', split:true, onRow: rows => this.permissionNameRef.load(rows)}) }
						</Box>
						<PermissionName onRef={ref=>this.permissionNameRef=ref} />
					</div>
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ title:'场景列表', labelWidth:'s7', width:400, api: 'conf-scene/add', editApi:'conf-scene/edit'  }) }
			</>
		)
	}
}

export default Index